package view;

import controller.SelfBookDetailsListener;
import pojo.Book;
import pojo.User;

import javax.swing.*;
import java.awt.*;

public class SelfBookDetails extends JDialog {
private JLabel labelID,labelName,labelWriter,labelPage,labelPrice,labelPress,labelClassification,labelSurplus;
private JTextField tfID,tfName,tfWriter,tfPage,tfPrice,tfPress,tfClassification,tfSurplus;
private Book book;
private User user;
private SelfBookDetailsListener selfBookDetailsListener;
    public SelfBookDetails(Book book, String userId, String userName) {
        selfBookDetailsListener =new SelfBookDetailsListener(this,userId,userName);
        this.book=book;
        this.setTitle("图书信息");
        this.setSize(400, 500);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setLayout(new BorderLayout());
        this.add(this.getPanel(),BorderLayout.CENTER);
        this.add(this.getButton(),BorderLayout.SOUTH);
    }
    public JPanel getPanel(){
        JPanel jPanel=new JPanel();
        jPanel.setLayout(new GridLayout(8,2));
        labelID=new JLabel("                             书号：");
        labelName=new JLabel("                             书名：");
        labelWriter=new JLabel("                             作者：");
        labelPage=new JLabel("                             页码：");
        labelPrice=new JLabel("                             价格：");
        labelPress=new JLabel("                           出版社：");
        labelClassification=new JLabel("                             类别：");
        labelSurplus=new JLabel("                             库存：");
        tfID=new JTextField(book.getBookId(),15);
        tfName=new JTextField(book.getBookName(),15);
        tfWriter=new JTextField(book.getWriter(),15);
        tfPage=new JTextField(book.getPage(),15);
        tfPrice=new JTextField(book.getPrice(),15);
        tfPress=new JTextField(book.getPress(),15);
        tfClassification=new JTextField(book.getClassification(),15);
        tfSurplus=new JTextField(book.getSurplus(),15);
        tfID.setEditable(false);
        tfClassification.setEditable(false);
        tfName.setEditable(false);
        tfPage.setEditable(false);
        tfPress.setEditable(false);
        tfPrice.setEditable(false);
        tfSurplus.setEditable(false);
        tfWriter.setEditable(false);
        jPanel.add(labelID);
        jPanel.add(tfID);

        jPanel.add(labelName);
        jPanel.add(tfName);

        jPanel.add(labelWriter);
        jPanel.add(tfWriter);

        jPanel.add(labelPage);
        jPanel.add(tfPage);

        jPanel.add(labelPrice);
        jPanel.add(tfPrice);

        jPanel.add(labelPress);
        jPanel.add(tfPress);

        jPanel.add(labelClassification);
        jPanel.add(tfClassification);

        jPanel.add(labelSurplus);
        jPanel.add(tfSurplus);

        return jPanel;
    }
    public JPanel getButton(){
        JButton jButton=new JButton("借阅");
        JButton jButton1=new JButton("返回");
        jButton.addActionListener(selfBookDetailsListener);
        jButton1.addActionListener(selfBookDetailsListener);
        JPanel jPanel=new JPanel();
        jPanel.add(jButton);
        jPanel.add(jButton1);
        return jPanel;
    }

    public Book getBook() {
        return book;
    }

    public User getUser() {
        return user;
    }
}
